// 进入该页面，传入id进来
// 通过url地址传入
let layer;
let form;
layui.use(['layer', 'form'], function () {
    layer = layui.layer;
    form = layui.form;


    let shuju = location.href.split("?");
    let str = shuju[1]
    let arr1 = str.split('&')
    // console.log(arr1);
    let arr2 = []
    let obj = {}
    arr1.forEach(function (item) {

        item.toString()
        // console.log(item);
        // console.log(item.split('='));
        arr2.push(item.split('='))
        // console.log(arr2);
    })

    arr2.forEach(function (item) {
        obj[item[0]] = item[1]
        console.log(obj[item[0]]);
    })

    // 数据回填
    // let user = obj[username]
    // let nick = obj[nickname]
    // let emai = obj[email]
    form.val("editForm", obj);

    // editForm  
    $(function () {
        // ****************************************编辑用户
        $('form').on('submit', function (e) {
            // 阻止默认行为
            e.preventDefault()

            let data = $(this).serialize()
            $.ajax({
                url: '/admin/users',
                type: 'PUT',
                data: data,
                success: function (res) {
                    if (res.status == 0) {
                        // 成功提示
                        layer.msg(res.message)
                        setTimeout(() => {
                            location.href = '/user/user.html';
                        }, 600);
                    }
                }
            })
        })
    })

})